﻿using nplJobsCommon.Employeer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Update
{
    public class  UpdateContactPerson : DataAccessBase
    {
        public EmployeerContactPerson EmployeerContactPerson { get; set; }
        public long checkUnique;

        public UpdateContactPerson()
        {
            StoredProcedureName = StoredProcedure.Name.spUpdateEmployeerContactPerson.ToString();
        }

        public void invoke()
        {
            EmployeerContactPersonUpdateDataParameters contactUpdateDataParameters = new EmployeerContactPersonUpdateDataParameters(this.EmployeerContactPerson);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = contactUpdateDataParameters.Parameters;
            dbHelper.RunScalar();

            if (contactUpdateDataParameters.Parameters[9].Value != null)
            {
                checkUnique = long.Parse(contactUpdateDataParameters.Parameters[9].Value.ToString());
            }
        }
    }

    #region SQL parameters for  employeer contact person insert data
    public class EmployeerContactPersonUpdateDataParameters
    {
        private EmployeerContactPerson EmployeerContactPerson;
        long checkUnique = 0;

        public EmployeerContactPersonUpdateDataParameters(EmployeerContactPerson employeerContactPerson)
        {
            this.EmployeerContactPerson = employeerContactPerson;
            Build();
        }

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@EmployeerID", EmployeerContactPerson.EmployeerID),
                    new SqlParameter("@ContactPersonID", EmployeerContactPerson.ContactPersonID),
                    new SqlParameter("@FirstName", EmployeerContactPerson.FirstName),
                    new SqlParameter("@LastName", EmployeerContactPerson.LastName),
                    new SqlParameter("@Email", EmployeerContactPerson.Email),
                    new SqlParameter("@ContactNumber", EmployeerContactPerson.ContactNumber),
                    new SqlParameter("@AlterNativeNumber", EmployeerContactPerson.AlternativeNumber),
                    new SqlParameter("@TitleID", EmployeerContactPerson.TitleID),
                    new SqlParameter("@DesignationID", EmployeerContactPerson.DesignationID),
                    new SqlParameter("@CheckUnique",checkUnique){ Direction =System.Data.ParameterDirection.Output}
                };

            Parameters = parameters;
        }

        public SqlParameter[] Parameters { get; set; }
    }
    #endregion
}


